package edu.gyc.hisecurity.controller;

import edu.gyc.hisecurity.model.User;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
@Slf4j
public class GirlController {


    @RequestMapping("/")
    public String menu() {
        return "index";
    }
    @RequestMapping("/index")
    public String index() {
        return "index";
    }
    @PostMapping("/getUserMenus")
    public String qipao(Model model) {
        log.info("getUserMenus called");
    User user=    ((User) SecurityContextHolder.getContext().getAuthentication().getPrincipal());
    log.info(user.getUsername()+" can access: "+user.getLoginUserMenus());
        model.addAttribute("menus", user.getLoginUserMenus());
        return "menu";
    }

    @GetMapping("/dba/hi")
    public String siwa() {
        return "dba/silk";
    }

    @GetMapping("/user/hi")
    public String userhi() {
        return "hello";
    }
    @GetMapping("/user/wa")
    public String a() {

        return "user/xr";
    }

    @GetMapping("/admin/hi")
    public String sex() {
      log.info("call /admin/hi");
        return "admin/wxm";
    }
    @GetMapping("/exit")
    public String exit() {

        log.info("called exit");
        return "exit";
    }
}
